package com.lixw.langchain.controller;

import cn.hutool.core.date.DateUtil;
import com.lixw.langchain.service.ChatPersistenceAssistant;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: ChatPersistenceController
 * @Description:
 * @Author: xuweiLi
 * @Create: 2025/8/24 14:04
 **/
@Slf4j
@RestController
public class ChatPersistenceController {
    @Resource
    private ChatPersistenceAssistant persistenceAssistant;

    @GetMapping("/chatPersistence/redis")
    public String testChatPersistence() {
        persistenceAssistant.chat(1L, "你好！我的名字是陈浩南");
        persistenceAssistant.chat(2L, "你好！我的名字是郭富城");

        String chat = persistenceAssistant.chat(1L, "我的名字是什么");
        System.out.println(chat);

        chat = persistenceAssistant.chat(2L, "我的名字是什么");
        System.out.println(chat);

        return "testChatPersistence success : "+ DateUtil.now();
    }


    @GetMapping("/chatWindow")
    public String testChatPersistenceWindow(@RequestParam("prompt") String prompt) {
        String chat = persistenceAssistant.chat(1L, prompt);
        System.out.println(chat);

        return "testChatPersistence success : "+ DateUtil.now();
    }
}